﻿using Microsoft.AspNetCore.SignalR;
using signalr.service.broker.ConnectionSql;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace signalr.service.broker.Hubs
{
    public class ChatHub:Hub
    {
        private readonly SqlDependencyContext dependencyContext;
        public ChatHub(SqlDependencyContext _dependencyContext)
        {
            dependencyContext = _dependencyContext;
        }
        public async Task SendMessage(string user, string message)
        {
            await Clients.All.SendAsync("ReceiveMessage", user, message);
        }
        public override Task OnDisconnectedAsync(Exception exception)
        {
            dependencyContext.Termination();
            return base.OnDisconnectedAsync(exception);
        }
    }
}
